
'use strict';

//app.mountpath  挂接

var express = require('express');

var app = express(); 
// app.get('/', function(req, res) {
//     res.send('Hello World!');
// });

// var user = express();
// user.get('/', function (req, res) {
//   console.log(user.mountpath); // [ '/adm*n', '/manager' ]
//   res.send('User Homepage');
// })

var admin = express();
admin.get('/', function (req, res) {
  console.log(admin.mountpath); // [ '/adm*n', '/manager' ]
  res.send('Admin Homepage');
})

var secret = express();
secret.get('/', function (req, res) {
  console.log(secret.mountpath); // /secr*t
  res.send('Admin Secret');
});

//当GET /user/42  http://localhost:3000/user/42
app.param('id', function(req, res, next, id) {
    console.log('CALLED ONLY ONCE');
    next();
});

app.get('/user/:id', function(req, res, next) {
    console.log('although this matches');
    next();
});

app.get('/user/:id', function(req, res) {
    console.log('and this mathces too');
    res.end();
});


admin.use('/secr*t', secret); // load the 'secret' router on '/secr*t', on the 'admin' sub app
app.use(['/adm*n', '/manager'], admin); // load the 'admin' router on '/adm*n' and '/manager', on the parent app
// app.use('/user', user);




var server = app.listen(3000, function() {
    var host = server.address().address;
    var port = server.address().port;

    console.log('Example app listening at http://%s:%s', host, port);
});
